package us.gaaoc.framework.webapp.backingbeans.clerk;
 
import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import us.gaaoc.framework.businessmodel.Filing;
import us.gaaoc.framework.dao.ModelFacadeHibernate; 
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * 
 * @author hea
 * @date Apr 26, 2006
 * @version: GAJE 1.5
 *
 */
@SuppressWarnings("unchecked")
public class ChildSupportTrashcanFilingPage extends BaseBackingBean {
 
	/**
	 * Property
	 */
	
	/** Generated Serial Version UID */
	private static final long serialVersionUID = -2815987006668927059L;
	
	private DataModel clearedFilingDataTable;
	
	private String courtUuid;
	
 	/**
 	 * Constructor
 	 *
 	 */
	public ChildSupportTrashcanFilingPage(){
		courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
		
		//case type = child support (1) 
		//List<Filing> clearedFilings = ModelFacadeHibernate.getInstance().findClearedCaseFilingsByType(1);		 
		//List<Filing> clearedFilings = this.getModelFacade().findClearedCaseFilings();
		List<Filing> clearedFilings = this.getModelFacade().findClearedCaseFilingsClerkSide(courtUuid);
		clearedFilingDataTable = new ListDataModel();
		clearedFilingDataTable.setWrappedData(clearedFilings);
	}	

	/**
	 * Getter for property clearedFilingDataTable
	 * @return clearedFilingDataTable
	 */
	public DataModel getClearedFilingDataTable() {
		return clearedFilingDataTable;
	}
	
	/**
	 * Setter for property clearedFilingDataTable
	 * @param clearedFilingDataTable
	 */
	public void setClearedFilingDataTable(DataModel clearedFilingDataTable) {
		this.clearedFilingDataTable = clearedFilingDataTable;
	}
  
  /**
   * Rhis method navigates user to the Case Details Page
   * @return String
   */
	public String gotoCaseDetailPage(){
		Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
	 	Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	sessionMap.put("caseUuid", caseUuid);
	 	sessionMap.put("from", "childSupportTrashCanPage");
	 	return "gotoCaseDetailsPage";
	}
	
	/**
	 * This method deletes case record from the list. (actually does not delete
	 * from database just changes the delete flag changed)
	 * @return String
	 */
	public String delete(){
	 	Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	ModelFacadeHibernate.getInstance().removeCaseRecord(caseUuid, courtUuid);
	 	//HibernatePhaseListener.getSessionFactory().getCurrentSession().getTransaction().commit();
		return "stay";		
	}
	
	/**
	 * This method restores the case record from the trash can page 
	 * which was cleared
	 * @return String
	 */
	public String restore(){
	 	Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	ModelFacadeHibernate.getInstance().updateCaseRecordForClearCase(caseUuid, false, courtUuid);
	 	//HibernatePhaseListener.getSessionFactory().getCurrentSession().getTransaction().commit();
		return "stay";	
	}
	
	/**
	 * This method navigates user to the previous page
	 * @return String
	 */
	public String back(){		
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		String fromPage = (String)sessionMap.get("from2");
		sessionMap.remove("from2");
		if(fromPage != null) {		
			if (fromPage.equalsIgnoreCase("receivedFiling"))
				return "receivedFiling";
			else if (fromPage.equalsIgnoreCase("importedFiling"))
				return "importedFiling";
			else if (fromPage.equalsIgnoreCase("rejectedFiling"))
				return "rejectedFiling";
			else if (fromPage.equalsIgnoreCase("servedFiling"))
				return "servedFiling";
			else if (fromPage.equalsIgnoreCase("nonServedFiling"))
				return "nonServedFiling";
			else if (fromPage.equalsIgnoreCase("disposedFiling"))
				return "disposedFiling";
			else if (fromPage.equalsIgnoreCase("appellateCaseTypePage"))
				return "appellateCaseTypePage";		
			else if (fromPage.equalsIgnoreCase("civilCaseTypePage"))
				return "civilCaseTypePage";
			else if (fromPage.equalsIgnoreCase("transmissionErrorFilingPage"))
				return "transmissionErrorFilingPage";
			
			return  "childEnforcement";
		}
		else 
			return  "childEnforcement";
	}
	
	/**
	 * This method navigates user to the Case Record History Page
	 * @return String
	 */
	public String gotoHistoryPage() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		Map requestMap = this.getFacesContext().getExternalContext()
				.getRequestParameterMap();
		String caseUuid = ((String) requestMap.get("caseUuid"));
		sessionMap.put("caseUuid", caseUuid);
		sessionMap.put("from", "ChildSupportTrashCanPage");
		return "gotoCaseHistoryPage";
	}
}
